package com.mmz.spring.aop.framework;



public class DefaultAopProxyFactory {
	
	public AopProxy createAopProxy(AdvisedSupport config)  {
		if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {
			Class<?> targetClass = config.getTargetClass();
			if (targetClass == null) {
				throw new RuntimeException("TargetSource cannot determine target class: " +
						"Either an interface or a target is required for proxy creation.");
			}
			if (targetClass.isInterface()) {
				return new JdkDynamicAopProxy(config);
			}
			//return new ObjenesisCglibAopProxy(config);
		}
		
		return new JdkDynamicAopProxy(config);
	}
	
	private boolean hasNoUserSuppliedProxyInterfaces(AdvisedSupport config) {
		Class<?>[] interfaces = config.getProxiedInterfaces();
		return (interfaces.length == 0 );
	}

}
